<template>
    <div>
      <router-link class="header-abs" tag="div" to="/">
        <div class="iconfont back-icon">&#xe624;</div>
      </router-link>
      <div class="header-fixed" v-show="showNavc" :style="opacityStyle">
        <router-link to="/">
          <div class="iconfont back-icon">&#xe624;</div>
        </router-link>
        地质公园
      </div>
    </div>
</template>

<script>
export default {
 name: 'DetailHeader',
  data () {
    return {
      showNavc: false,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  },
  methods: {
    handleScroll () {
      let top = document.documentElement.scrollTop
      if (top > 60) {
        let opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.showNavc = true
      } else {
        this.showNavc = false
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl';
  .header-abs {
    position: absolute;
    left: .2rem;
    top: .2rem;
    width: .8rem;
    height: .8rem;
    border-radius: .4rem;
    background: rgba(0, 0, 0, .8);
    line-height: .8rem;
    text-align: center;
  }
  .back-icon {
    color: white;
    font-size: .4rem;
  }
  .header-fixed {
    line-height: $headerHeight;
    height: $headerHeight;
    background: $bgColor;
    text-align: center;
    color: #fff;
    font-size: .32rem;
    overflow: hidden;
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
  }
  .back-icon {
    width: .64rem;
    text-align: center;
    font-size: .4rem;
    position: absolute;
    top: 0;
    left: 0;
    color: #fff;
  }
</style>
